//
// Created by 17775 on 2024/10/18.
//

#ifndef RAYCI_BEAM_STABILITY_VIEW_H
#define RAYCI_BEAM_STABILITY_VIEW_H

#include <QDockWidget>
#include <QGridLayout>
#include "../../qcustomplot.h"
#include "../../Common/commonchart.h"
#include "../../Common/common_chart_options.h"
#include "../../Common/common_statistics_chart.h"


QT_BEGIN_NAMESPACE
namespace Ui { class Beam_Stability_View; }
QT_END_NAMESPACE

class Beam_Stability_View : public QDockWidget {
Q_OBJECT

signals:
    void stopBeamStabilityThread();
    void reportBeamStability();
    void BeamStabilityClicked();

public:
    explicit Beam_Stability_View(QWidget *parent = nullptr);
    ~Beam_Stability_View() override;
    void setWindowTitleName(const QString& name);

//    QList<CommonChart*> charts = {
//            new CommonChart(this),  // peakChart
//            new CommonChart(this),  // powerChart
//            new CommonChart(this),  // cxChart
//            new CommonChart(this),  // cyChart
//            new CommonChart(this),  // majorChart
//            new CommonChart(this),  // minorChart
//            new CommonChart(this)   // angleChart
//    };
    QList<Common_Statistics_Chart*> charts = {
            new Common_Statistics_Chart(this),  // peakChart
            new Common_Statistics_Chart(this),  // powerChart
            new Common_Statistics_Chart(this),  // cxChart
            new Common_Statistics_Chart(this),  // cyChart
            new Common_Statistics_Chart(this),  // majorChart
            new Common_Statistics_Chart(this),  // minorChart
            new Common_Statistics_Chart(this)   // angleChart
    };
    QList<Common_Chart_Options*> options = {
            new Common_Chart_Options(this->parentWidget()),  // peakChartOptions
            new Common_Chart_Options(this->parentWidget()),  // powerChartOptions
            new Common_Chart_Options(this->parentWidget()),  // cxChartOptions
            new Common_Chart_Options(this->parentWidget()),  // cyChartOptions
            new Common_Chart_Options(this->parentWidget()),  // majorChartOptions
            new Common_Chart_Options(this->parentWidget()),  // minorChartOptions
            new Common_Chart_Options(this->parentWidget())   // angleChartOptions
    };

    void mousePressEvent(QMouseEvent *event);

    void refreshChart();
    void closeEvent(QCloseEvent *event) override;
    void initCommonChart();

private:
    Ui::Beam_Stability_View *ui;
    QWidget* menuPanel = nullptr;
    QVBoxLayout* menuLayout = nullptr;
    QWidget* centralWidget = nullptr;
    QHBoxLayout* mainLayout = nullptr;
    QPushButton* btnSave = nullptr;
    QPushButton* btnExport = nullptr;
    QPushButton* btnZoomReset = nullptr;
    QPushButton* btnMaximumIntensity = nullptr;
    QPushButton* btnPower = nullptr;
    QPushButton* btnCentroid = nullptr;
    QPushButton* btnBeamWidth = nullptr;
    QPushButton* btnReport = nullptr;
    QSplitter* mainSplitter = nullptr;
    QSplitter* leftSplitter = nullptr;
    QSplitter* rightSplitter = nullptr;
    QSplitter* rightInnerSplitter = nullptr;
    bool maxIntensity = false;
    bool maxPower = false;
    bool centroidIsHide = false;
    bool beamWidthIsHide = false;
    void maximumIntensity();
    void maximumPower();
    void hideCentroid();
    void hideBeamWidth();
};

#endif //RAYCI_BEAM_STABILITY_VIEW_H